import { EChartsOption } from 'echarts'

//option--安全金字塔chart
export const  pyramidOptions: EChartsOption = {
  
    color: [ "#FF0000", "#FFC000", "#FFFF00", "#92D050", "#00B0F0"],
  
    series: [

      {
        name: "TIT",
        type: "funnel",
        left: '3%',
        top:'33%',
        width: "90%",
        height:'60%',
        maxSize: "100%",
        sort: "ascending",
        label: {
            position:'inside',
            formatter: "\n{b}",
            color:'#000000',
            fontSize:9,
            //verticalAlign:'bottom',
            padding:0,
        },
        labelLine: {
          
            show: true,
            length: 30,
          
        },
        itemStyle: {
          
            opacity: 1,
          
        },
        tooltip: {
          show: false,
        },
  
        data: [
        
          {
            value: 30,
            name: "LTI",
          },
          {
            value: 60,
            name: "MTI",
          },
          {
            value: 90,
            name: "MI",
          },
          {
            value: 120,
            name: "NMI",
          },
          {
            value: 150,
            name: "PHI",
          },
        ],
      },
  
      
    ],
  
}


//横坐标--当月每日
export const dayData = ["YTD","M1","M2","M3"];

//计算当月的天数
function getDaysInMonth(): number {
  const currentDate = new Date();
  
  const currentY = currentDate.getFullYear();
  const currentM = currentDate.getMonth()+1;
  const MonthDayNum = new Date(currentY,currentM,0).getDate();  //计算当月的天数

  return MonthDayNum;
}
for (let j = 1; j < getDaysInMonth()+1; j++) {

  dayData.push(j+'')

}

// ---------------------------看板数据填充，待删除
const BVFPYTarget:any = [];
const HMFPYTarget:any = [];  

  
for (let i = 0; i < 34; i++) {
  BVFPYTarget.push(98);
  HMFPYTarget.push(99);
}
// ---------------------------


//图表目标（target）数据函数
export const TargetData  = (TargetArray:any,xAxisDataLength:any)=>{

  const Target:any = [];
  for (let i = 0; i < xAxisDataLength ; i++) {
      
    Target.push(TargetArray[0]);

  }
  return Target;
}

//每日班次图表横坐标--一周每天班次

export const ShiftData = [

  "Day",
  "Eve",
  
  "Day",
  "Eve",
  
  "Day",
  "Eve",
  
  "Day",
  "Eve",
  
  "Day",
  "Eve",
  
  "Day",
  "Eve",
  
  "Day",
  "Eve",

]

//每日班次图表副横坐标--每周工作日
export const WeekData = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

//echart图表图列颜色
const ColorList = ["#00B0F0","#000000","#FF0000","#92D050"]
//普通图表（针对绩效看板第一行图表）+库存图表
export const BarLineChart  = (xAxisData:any,Component:any ,yAxisMin:any,yAxisMax:any,Legend?:any)=>{

  const ORIGSeries = [

    {
      name: Legend?Legend[0]:"",
      type: "bar",
      barMaxWidth:Component.contenttitle === '库存'?'30%':'',
      itemStyle:{
        color:ColorList[0]
      },
      data: Component.echartData.data
    },
    
    {
      name: Legend?Legend[1]:"",
      type: "line",
      data: TargetData(Component.echartData.target,xAxisData.length),
      itemStyle:{
        color:ColorList[1]
      },
      symbol:'none'
    },
    
  ]

  return {
    grid: {
      left: Component.contenttitle === '库存'? "12%" : "8%",
      top:'6%',
      width:Component.contenttitle === '库存'?'86%':'90%',
      height:'82%',
      show:false
    },
    padding:[],
      //color: [ "#00B0F0",'#000000',"#FF0000","#92D050"],
      // legend: {
      //   //data: ["Near Miss", "Pot.Hazards"],
      //   align:'right',
      //   bottom:'8%',
      //   itemHeight:6,
      //   itemWidth:6,
      //   //width:20,
      //   textStyle:{
      //     fontSize:5,
      //   },
      // },
      xAxis: [
        {
          type: "category",
          boundaryGap:true,
          axisTick: {
            show:false,
            //alignWithLabel: true
          },
          axisLabel:Component.contenttitle === '库存'?{interval:0,fontSize:6}:{
            interval:0,
            rotate: 45, //旋转标签，减少重叠
            fontSize:6,
          },
          nameTextStyle:{
            //padding:1,
          },
          
          data: xAxisData,
            
        },
      ],
      yAxis: [
        
        {
          type: "value",
          min: yAxisMin,
          max: yAxisMax,
        
          splitLine:{
            show:false,
          },
          axisLine: {

            lineStyle: {
              color: '#000000',
            },
          },
          axisLabel: Component.contenttitle === '库存'?{fontSize:7}:{
            formatter: "{value}% ",
            fontSize:7,
          },
        },
      ],
      series: ORIGSeries,

  }

}


//OEE图表
// export const OEEChart  = (Component:any )=>{

//   return{

//     grid:{
//       left:'7%',
//     },
//     xAxis: [{
//         type: 'category',
//         data: Component.echartData.OEExAxis,
//         axisLabel: {
//           interval:0,
//           fontSize:6,
//         },
//         axisTick: {
//           show:false,
//         },
        
//     }, 
//     {
//         type: 'category',
//         show: false,
//         boundaryGap: false,
//         data: Component.echartData.OEExAxis
//     }
//     ],
//     yAxis: [{
//         type: 'value',
//         boundaryGap: [0, 0.1],
//         splitLine: {
//           show:false
//         },
//         axisLabel: {
//           fontSize:7,
//       },
  
//     }, 
//     {
//         type: 'value',
//         //name: '累积百分比',
//         axisLabel: {
//             formatter: '{value} %',
//             fontSize:7,
//         },
//         splitLine: {
//           show:false
//         }
//     }],
//     series: [{
//         //name: '频率',
//         type: 'bar',
//         //xAxisIndex: 0,
//         data: Component.echartData.BVdata,
//         itemStyle: {
          
//           color: '#E2000F', // 折线颜色
      
//         },
//     }, {
//         name: '累积百分比',
//         type: 'line',
//         xAxisIndex: 1,
//         yAxisIndex: 1,
//         data: Component.echartData.BVtarget,
//         //symbolOffset:[0,'-50%'],
//         label: {
          
//               show: true, // 显示标签
//               position: 'top', // 标签位置在数据点的上方
//               formatter: function (param) {
//                   return (param.value + '%');
//               },
//               backgroundColor:'none',
//               fontSize:8,
//       },
//       itemStyle: {
          
//               color: '#FFC000', // 折线颜色
          
//       },
//     }]
//   }
  

// }



//每日班次图表
export const DailyShiftChart  = (MainxAxisData:any,SubxAxisData:any,Component:any ,yAxisMin:any,yAxisMax:any,Legend?:any )=>{

  const OriginalSeries = [

    {
      name: Legend?Legend[0]:"",
      type: "bar",
      xAxisIndex: 0,
      itemStyle:{
        color:ColorList[0]
      },
      data: Component.echartData.data
    },
    
    //针对"潜在风险&虚惊事件"图表只能输出BV&HM综合数据，图表柱子可以沾满一个格，不会留半个给HMdtata
    Legend && Legend[1]?{
      name: Legend?Legend[1]:"",
      xAxisIndex: 0,
      type: "bar",
      itemStyle:{
        color:ColorList[2]
      },
      data: Component.echartData.overtime
    }:null,
  
    {
      name: Legend?Legend[2]:"",
      xAxisIndex: 0,
      type: "line",
      data: TargetData(Component.echartData.target,MainxAxisData.length),
      itemStyle:{
        color:ColorList[1]
      },
      symbol:'none'
    },
    {
      name: Legend?Legend[3]:"",
      xAxisIndex: 0,
      type: "line",
      data: Component.echartData.absent,
      itemStyle:{
        color:ColorList[3]
      },
      symbol:'none'
    }
  
  ];

  const BarLineSeries = OriginalSeries.filter((item:any):any =>{

    
    if(item !== null && item.name ==="Pot.Hazards"){
      item.data = Component.echartData.target
    }

    return item !== null

  })

  return{

    grid:Component.contenttitle ==='报废数量' || Component.contenttitle ==='实际产出'? {
      left: "8%",
      top:'6%',
      width:'90%',
      height:'75%',
      show:false
    }:{left: "8%",top:'6%',height:'75%',show:false},
    
    legend: {
      //data: ["Near Miss", "Pot.Hazards"],
      orient: 'vertical', // 设置图例纵向排列
      right:'right',
      top:'8%',
      itemHeight:6,
      itemWidth:6,
      //width:20,
      textStyle:{
        fontSize:5,
      },
    },
  
    xAxis: [
      {
        type: "category",
        //z: 1,
        data: MainxAxisData,
        position: "bottom",
        offset: 0,
        splitArea: {
          show: false,
        },
        splitLine: {
          show: false,
        },
        axisTick: {
          length: 15, //早晚中间的分界线 必须是图表显示区域高度
          lineStyle: {
            width: 0.3,
          },
        },
        axisLabel: {
          interval: 0,   
          fontSize: 6,
          //margin: 5, //刻度标签与轴线之间的距离。
        },
        // axisLine: {
        //   show: false,
        //   lineStyle: {
        //     // color: '#ddd', // 颜色
        //     // width: 0.5 // 粗细
        //   },
        // },
      },
  
      {
        type: "category",
        //z: 1,
        data: SubxAxisData,
        position: "bottom",
        offset: 32,
        splitArea: {
          show: false,
        },
        splitLine: {
          show: false,
        },
        axisLabel: {
          interval: 0,
          fontSize:6,
          margin: -7, //刻度标签与轴线之间的距离。
        },
        //刻度轴是否显示,以及设置长度
        axisTick: {
          show: true,
          length: -25, //每日分界线
          lineStyle: {
            width: 0.3,
          },
        },
        axisLine: {
          show: false,
          lineStyle: {
            // color: '#ddd', // 颜色
            // width: 0.5 // 粗细
          },
        },
      },
  
    ],
  
    yAxis: [
      
      {
        type: "value",
        min: yAxisMin,
        max: yAxisMax,
        //show:true,
        //scale: true,
        //position: "left",
        // nameTextStyle:{
        //   fontSize:7,
        // },
        splitLine:{
          show:false,
        },
        axisLine: {
  
          lineStyle: {
            color: '#000000',
          },
        },
        axisLabel: {
          formatter: '{value}',
          fontSize:7,
        },
      },
    ],
  
    series: BarLineSeries,

  }

}

export const trial = () => {
  console.log(pyramidOptions)
}